﻿namespace DomainServices.Tools.Pdb.SymStore
{
    using System;
    using System.Diagnostics.SymbolStore;

    internal class SymScope : ISymbolScope2, ISymbolScope
    {
        private ISymUnmanagedScope m_target;

        internal SymScope(ISymUnmanagedScope target)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            this.m_target = target;
        }

        public ISymbolScope[] GetChildren()
        {
            int num;
            this.m_target.GetChildren(0, out num, null);
            ISymUnmanagedScope[] children = new ISymUnmanagedScope[num];
            this.m_target.GetChildren(num, out num, children);
            ISymbolScope[] scopeArray2 = new ISymbolScope[num];
            for (int i = 0; i < num; i++)
            {
                scopeArray2[i] = new SymScope(children[i]);
            }
            return scopeArray2;
        }

        public ISymbolConstant[] GetConstants()
        {
            int num;
            ((ISymUnmanagedScope2) this.m_target).GetConstants(0, out num, null);
            ISymUnmanagedConstant[] constants = new ISymUnmanagedConstant[num];
            ((ISymUnmanagedScope2) this.m_target).GetConstants(num, out num, constants);
            ISymbolConstant[] constantArray2 = new ISymbolConstant[num];
            for (int i = 0; i < num; i++)
            {
                constantArray2[i] = new SymConstant(constants[i]);
            }
            return constantArray2;
        }

        public ISymbolVariable[] GetLocals()
        {
            int num;
            this.m_target.GetLocals(0, out num, null);
            ISymUnmanagedVariable[] locals = new ISymUnmanagedVariable[num];
            this.m_target.GetLocals(num, out num, locals);
            ISymbolVariable[] variableArray2 = new ISymbolVariable[num];
            for (int i = 0; i < num; i++)
            {
                variableArray2[i] = new SymVariable(locals[i]);
            }
            return variableArray2;
        }

        public ISymbolNamespace[] GetNamespaces()
        {
            int num;
            this.m_target.GetNamespaces(0, out num, null);
            ISymUnmanagedNamespace[] namespaces = new ISymUnmanagedNamespace[num];
            this.m_target.GetNamespaces(num, out num, namespaces);
            ISymbolNamespace[] namespaceArray2 = new ISymbolNamespace[num];
            for (int i = 0; i < num; i++)
            {
                namespaceArray2[i] = new SymNamespace(namespaces[i]);
            }
            return namespaceArray2;
        }

        public int ConstantCount
        {
            get
            {
                int num;
                ((ISymUnmanagedScope2) this.m_target).GetConstantCount(out num);
                return num;
            }
        }

        public int EndOffset
        {
            get
            {
                int num;
                this.m_target.GetEndOffset(out num);
                return num;
            }
        }

        public int LocalCount
        {
            get
            {
                int num;
                this.m_target.GetLocalCount(out num);
                return num;
            }
        }

        public ISymbolMethod Method
        {
            get
            {
                ISymUnmanagedMethod pRetVal = null;
                this.m_target.GetMethod(out pRetVal);
                if (pRetVal == null)
                {
                    return null;
                }
                return new SymMethod(pRetVal);
            }
        }

        public ISymbolScope Parent
        {
            get
            {
                ISymUnmanagedScope pRetVal = null;
                this.m_target.GetParent(out pRetVal);
                if (pRetVal == null)
                {
                    return null;
                }
                return new SymScope(pRetVal);
            }
        }

        public int StartOffset
        {
            get
            {
                int num;
                this.m_target.GetStartOffset(out num);
                return num;
            }
        }
    }
}

